1 package net.sourceforge.simplegamenet.dice;
2
3 import javax.swing.*;
4 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
5 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
6
7 public class DiceScoreTotalPanel extends JPanel {
8
9 private DicePlayerClient dicePlayerClient;
10 private DiceScoreComponent[] diceScoreTotalComponents = new DiceScoreComponent[8];
11 private JLabel totalsLabel = new JLabel("Totals: ");
12 private JLabel[] playerTotalNickLabels = new JLabel[8];
13 private Integer[] diceParticipantIDs;
14
15 DiceScoreTotalPanel(DicePlayerClient dicePlayerClient) {
16 this.dicePlayerClient = dicePlayerClient;
17 ProportionLayout layout = new ProportionLayout();
18 layout.appendColumn(5);
19 layout.appendColumn(0, ProportionLayout.NO_PROPORTION);
20 layout.appendColumn(10);
21 for (int i = 0; i < 8; i++) {
22 layout.appendColumn(20, 1.0);
23 }
24 layout.appendColumn(5);
25 layout.appendRow(5);
26 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
27 layout.appendRow(10);
28 layout.appendRow(20, 1.0);
29 layout.appendRow(5);
30 setLayout(layout);
31
32 add(totalsLabel, new ProportionConstraints(1, 3));
33 for (int i = 0; i < 8; i++) {
34 playerTotalNickLabels[i] = new JLabel();
35 diceScoreTotalComponents[i] = new DiceScoreComponent(false);
36 add(diceScoreTotalComponents[i], new ProportionConstraints((i + 3), 3));
37 }
38 showScoreTotalCases();
39 }
40
41 public void showScoreTotalCases() {
42 for (int i = 0; i < 8; i++) {
43 diceScoreTotalComponents[i].setBorder(BorderFactory.createEtchedBorder());
44 }
45 }
46
47 public void setScoreTotalCases() {
48 diceParticipantIDs = dicePlayerClient.getDiceParticipantIDs();
49 int amountValues = dicePlayerClient.getDicePlayerAmount();
50 for (int i = 0; i < 8; i++) {
51 diceScoreTotalComponents[i].setScoreLabel("");
52 diceScoreTotalComponents[i].setBorder(BorderFactory.createEtchedBorder());
53 }
54 for (int i = amountValues; i < 8; i++) {
55 if (i >= 8) {
56 break;
57 } else {
58 diceScoreTotalComponents[i].setBorder(BorderFactory.createLoweredBevelBorder());
59 }
60 }
61 }
62
63 public void setPlayerNicknames() {
64 setScoreTotalCases();
65 Integer firstPlayer = dicePlayerClient.getNextPlayer();
66 String dicePlayerNickname = new String("");
67 for (int i = 0; i < diceParticipantIDs.length; i++) {
68 dicePlayerNickname = (i + 1) + ". " + dicePlayerClient.getDicePlayerNickname(
69 diceParticipantIDs[i]);
70 playerTotalNickLabels[i].setText(dicePlayerNickname);
71 add(playerTotalNickLabels[i], new ProportionConstraints((i + 3), 1));
72 }
73 }
74
75 public void fillTotal(int playerTotal) {
76 for (int i = 0; i < diceParticipantIDs.length; i++) {
77 if (dicePlayerClient.getNextPlayer().equals(diceParticipantIDs[i])) {
78 diceScoreTotalComponents[i].setTotalScoreLabel(new Integer(playerTotal).toString());
79 }
80 }
81 }
82 }